<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<?php
// check if the user is logged-in
include 'authentication.php';
isAuthorized();

$parent_dir = $_GET['parent_dir'];
$idl = $_GET['idl'];

include_once($_SERVER["DOCUMENT_ROOT"]."/web-doc/protected/database/MySqlDAO.php");
include_once("../utils/redirect.php");

$mySqlDAO = new MySqlDAO();

if ($parent_dir) {
    if (!empty($_POST['isToInsert'])) {
        if (!empty($_POST['title']) && !empty($_POST['url'])) {
            $title = $_POST['title'];
            $url = $_POST['url'];

            $idlres = checkLinkTitle($parent_dir, $title);
            if(!empty($idlres) && $idlres!=$idl) {
                echo "Il nome <b>$title</b> è già usato per un'altro link. Scegliere un'altro nome.<br>";
            }
            else {
                 modifyLink($idl, $title, $url, $parent_dir);
                 redirect("showcategory.php?idc=$parent_dir",FALSE);
            }
        } else {
            echo "ATTENZIONE: Inserire tutti i dati.";
        }
    }
} else {
    die("ERRORE: Parent directory mancante. <a href=javascript:history.back(-1)>Indietro</a>");
}

$link = $mySqlDAO->getLink($idl);
list($title, $url) = mysql_fetch_array($link);


?>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="../styles/main.css">
        <link rel="stylesheet" type="text/css" href="../styles/admin.css">
        <title>WebDoc - Modify link</title>
    </head>
    <body>
        <?php
            $formaction = "modifylink.php?parent_dir=$parent_dir&idl=$idl";
        ?>
        <form method="post" enctype="multipart/form-data" action="<?php echo $formaction ?>">
            <table width="450" border="0" cellpadding="1" cellspacing="1" class="box">
                <tr>
                    <td valign="top" colspan="2">
                        Nome link: <input type="text" name="title" size="50" maxlength="255" value="<?php echo $title ?>">
                        <input type="hidden" name="isToInsert" value="true">
                    </td>
                </tr>
                <tr>
                    <td valign="top" colspan="2">
                        URL: <input type="text" name="url" size="50" maxlength="255" value="<?php echo $url ?>">
                    </td>
                </tr>
                <tr>
                    <td width="80" colspan="2">
                        <br><br>
                        <input type="submit" value="Modifica" />
                        <!--<input name="upload" type="submit" class="box" id="upload" value=" Upload ">-->
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

